//
//  UIBarButtonItem+Ext.swift
//  TTCOM-iOS
//
//  Created by Toj on 5/26/22.
//

import UIKit

public extension UIBarButtonItem {
    
    convenience init(target: Any, action: Selector, for envents: UIControl.Event, imageNormal: String = "", imageSelected: String = "", imageHighlighted: String = "") {
        let view = UIButton()
        view.addTarget(target, action: action, for: envents)
        
        if imageNormal.count > 0 {
            let image = UIImage(named: imageNormal)
            view.setBackgroundImage(image, for: .normal)
        }
        
        if imageSelected.count > 0 {
            let image = UIImage(named: imageSelected)
            view.setBackgroundImage(image, for: .selected)
        }
        
        if imageHighlighted.count > 0 {
            let image = UIImage(named: imageHighlighted)
            view.setBackgroundImage(image, for: .highlighted)
        }
        
        view.sizeToFit()
        
       self.init(customView: view)
    }
}
